package com;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;

import java.io.IOException;

@SpringBootApplication
public class ExcelPagerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ExcelPagerApplication.class, args);

    }
    @Value("${server.port}")
    private String appport;  //站点端口号

    /*当端口启动后，直接跳转界面*/
    @EventListener({ApplicationReadyEvent.class})
    void applicationReadyEvent() {
        System.out.println("应用已经准备就绪  启动浏览器");
        String url = "http://localhost:" + appport;
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
        } catch (IOException e) {
            System.out.println("功能出现错误，请手动在浏览器输入localhost:8006使用");
//            e.printStackTrace();
        }
}}
